import Vue from 'vue'
import VueI18n from 'vue-i18n'
import eleLocale from 'element-ui/lib/locale'; //兼容element
import { localRead } from '@/libs/util'
import customZhCn from './lang/zh-CN'
import customZhTw from './lang/zh-TW'
import customEnUs from './lang/en-US'
// import zhCnLocale from 'iview/src/locale/lang/zh-CN'
// import enUsLocale from 'iview/src/locale/lang/en-US'
import zhTwLocale from 'iview/src/locale/lang/zh-TW'
import zhCnLocale from 'view-design/dist/locale/zh-CN';
import enUsLocale from 'view-design/dist/locale/en-US';

import ElzhCnLocale from 'element-ui/src/locale/lang/zh-CN';
import ElzhTwLocale from 'element-ui/src/locale/lang/zh-TW';
import ElenUsLocale from 'element-ui/src/locale/lang/en';
Vue.use(VueI18n)

const navLang = navigator.language
const localLang = (navLang === 'zh-CN' || navLang === 'en-US') ? navLang : false
let lang = localLang || localRead('local') || 'zh-CN'

Vue.config.lang = lang

Vue.locale = () => {}
const messages = {
    'zh-CN': Object.assign(zhCnLocale, customZhCn, ElzhCnLocale),
    'zh-TW': Object.assign(zhTwLocale, customZhTw, ElzhTwLocale),
    'en-US': Object.assign(enUsLocale, customEnUs, ElenUsLocale)
}
const i18n = new VueI18n({
    locale: lang,
    messages
})

eleLocale.i18n((key, value) => i18n.t(key, value)) //兼容element
export default i18n